package com.linciping.sample.useges;

import com.intellij.find.FindModel;
import com.intellij.find.impl.FindInProjectUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.usageView.UsageInfo;
import com.intellij.usages.FindUsagesProcessPresentation;
import com.intellij.usages.UsageInfo2UsageAdapter;
import com.intellij.usages.UsageInfoAdapter;
import com.intellij.usages.UsageViewPresentation;
import com.intellij.util.Processor;

public class UsegesByTextAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        Project project = e.getProject();
        assert project != null;
        FindModel findModel = new FindModel();
        FindModel.initStringToFind(findModel, "ss");
        UsageViewPresentation usageViewPresentation = FindInProjectUtil.setupViewPresentation(findModel);
        final FindUsagesProcessPresentation processPresentation =
                FindInProjectUtil.setupProcessPresentation(project, usageViewPresentation);
        FindInProjectUtil.findUsages(findModel, project, new Processor<UsageInfo>() {
            @Override
            public boolean process(UsageInfo usageInfo) {
                UsageInfoAdapter usageInfoAdapter= (UsageInfoAdapter) UsageInfo2UsageAdapter.CONVERTER.fun(usageInfo);
                return true;
            }
        }, processPresentation);
    }
}
